package org.ruanjj.baseknowleadgedemo;


public class InstanceObjectByClone implements Cloneable{
    Address address;

    public InstanceObjectByClone(Address address){
        this.address = address;
    }

    public String getAddress(){
        return address.name;
    }

    /*@Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();// 默认浅拷贝
    }*/

    //实现深拷贝
    @Override
    protected Object clone() throws CloneNotSupportedException {
        InstanceObjectByClone cloned = (InstanceObjectByClone) super.clone();
        cloned.address = (Address) address.clone();
        return cloned;
    }
}
